<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Bomberman:  Fichier source de /home/ph3w/Bureau/lif7-bomberman/ClientServer/class_BaseClientServer.cpp</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Généré par Doxygen 1.7.1 -->
<script type="text/javascript">
function hasClass(ele,cls) {
  return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}

function addClass(ele,cls) {
  if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}

function removeClass(ele,cls) {
  if (hasClass(ele,cls)) {
    var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
    ele.className=ele.className.replace(reg,' ');
  }
}

function toggleVisibility(linkObj) {
 var base = linkObj.getAttribute('id');
 var summary = document.getElementById(base + '-summary');
 var content = document.getElementById(base + '-content');
 var trigger = document.getElementById(base + '-trigger');
 if ( hasClass(linkObj,'closed') ) {
   summary.style.display = 'none';
   content.style.display = 'block';
   trigger.src = 'open.png';
   removeClass(linkObj,'closed');
   addClass(linkObj,'opened');
 } else if ( hasClass(linkObj,'opened') ) {
   summary.style.display = 'block';
   content.style.display = 'none';
   trigger.src = 'closed.png';
   removeClass(linkObj,'opened');
   addClass(linkObj,'closed');
 }
 return false;
}
</script>
<div class="header">
  <div class="headertitle">
<h1>/home/ph3w/Bureau/lif7-bomberman/ClientServer/class_BaseClientServer.cpp</h1>  </div>
</div>
<div class="contents">
<a href="class___base_client_server_8cpp.html">Aller à la documentation de ce fichier.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#include &quot;<a class="code" href="class___base_client_server_8h.html">class_BaseClientServer.h</a>&quot;</span>
<a name="l00002"></a>00002 <span class="preprocessor">#include &quot;../debug.h&quot;</span>
<a name="l00003"></a>00003 
<a name="l00004"></a>00004 IF_WINDOWS(
<a name="l00005"></a>00005     WSADATA baseClientServer::c_wsaData;
<a name="l00006"></a>00006 )
<a name="l00007"></a>00007 
<a name="l00008"></a>00008 <span class="comment">// Permet de déconnecter tout les client, de décharger Winsock de la mémoire, puis de rapporter une erreur + exit</span>
<a name="l00009"></a>00009 #define reportError( ... ) {this-&gt;~<a class="code" href="classbase_client_server.html" title="Support pour la création d&amp;#39;une class client/serveur.">baseClientServer</a>(); stdErrorE( __VA_ARGS__ )}
<a name="l00010"></a>00010 
<a name="l00011"></a>00011 
<a name="l00012"></a>00012 <span class="comment">/***************************************************************************/</span><span class="comment">/*!</span>
<a name="l00013"></a>00013 <span class="comment">* @fn baseClientServer::baseClientServer()</span>
<a name="l00014"></a>00014 <span class="comment">* @brief Constructeur par defaut</span>
<a name="l00015"></a>00015 <span class="comment">*</span>
<a name="l00016"></a>00016 <span class="comment">* - Si la platforme est windows =&gt; on charge Winsock en mémoire</span>
<a name="l00017"></a>00017 <span class="comment">* - Paramétrage pas défaut.</span>
<a name="l00018"></a>00018 <span class="comment">*/</span>
<a name="l00019"></a>00019 <a class="code" href="classbase_client_server.html#ada968cd92346f898f60216c738da2737">baseClientServer::baseClientServer</a>()
<a name="l00020"></a>00020 {
<a name="l00021"></a>00021     <a class="code" href="classbase_client_server.html#a6415a999d34d9969e6b7d7108df74c0f">IF_WINDOWS</a>(
<a name="l00022"></a>00022         <span class="comment">// MAKEWORD(2, 2) := La version que l&#39;on veux avoir (2.2)</span>
<a name="l00023"></a>00023         <span class="comment">// Démarrage winsock</span>
<a name="l00024"></a>00024         <span class="keywordtype">int</span> err = WSAStartup(MAKEWORD(2, 2), &amp;c_wsaData);
<a name="l00025"></a>00025         <span class="keywordflow">if</span>( err )
<a name="l00026"></a>00026             stdErrorE(<span class="stringliteral">&quot;Erreur(%d) lors du démmarage de WinSock&quot;</span>, err);
<a name="l00027"></a>00027         <span class="comment">//stdError(&quot;Info sur le serveur: wVersion=%u, wHighVersion=%u, szDescription=%s, szSystemStatus=%s&quot;, c_wsaData.wVersion, c_wsaData.wHighVersion, c_wsaData.szDescription, c_wsaData.szSystemStatus);</span>
<a name="l00028"></a>00028 
<a name="l00029"></a>00029         <span class="keywordflow">if</span>( LOBYTE(c_wsaData.wVersion) != 2 || HIBYTE(c_wsaData.wVersion) != 2 )
<a name="l00030"></a>00030             stdError(<span class="stringliteral">&quot;La version WinSock 2.2 n&#39;est pas disponnible sur cette ordinateur.&quot;</span>);
<a name="l00031"></a>00031     );
<a name="l00032"></a>00032 
<a name="l00033"></a>00033     c_wait.tv_sec = 0;
<a name="l00034"></a>00034     c_wait.tv_usec = 10000;<span class="comment">// 0.01 secondes</span>
<a name="l00035"></a>00035 
<a name="l00036"></a>00036 
<a name="l00037"></a>00037     <a class="code" href="classbase_client_server.html#adcdb18e66a3751fd8edbd5d1f65e8bd3" title="Le socket principal. ( c&amp;#39;est clui là quit sert pour l&amp;#39;écoute sur le port c_port )...">c_listenSocket</a> = 0;
<a name="l00038"></a>00038     <a class="code" href="classbase_client_server.html#a2dea81cee139f918358e36b8650fa37e" title="&amp;lt; Temps d&amp;#39;attente au niveau du select">c_port</a> = 0;
<a name="l00039"></a>00039 }
<a name="l00040"></a>00040 
<a name="l00041"></a>00041 
<a name="l00042"></a>00042 <span class="comment">/***************************************************************************/</span><span class="comment">/*!</span>
<a name="l00043"></a>00043 <span class="comment">* @fn baseClientServer::~baseClientServer()</span>
<a name="l00044"></a>00044 <span class="comment">* @brief Destructeur par defaut</span>
<a name="l00045"></a>00045 <span class="comment">*</span>
<a name="l00046"></a>00046 <span class="comment">* - Appel baseClientServer::endListen()</span>
<a name="l00047"></a>00047 <span class="comment">* - Si la platforme est windows =&gt; on décharge Winsock de la mémoire</span>
<a name="l00048"></a>00048 <span class="comment">*/</span>
<a name="l00049"></a><a class="code" href="classbase_client_server.html#ab05d86575998b22718aad38aec0027d4">00049</a> <a class="code" href="classbase_client_server.html#ab05d86575998b22718aad38aec0027d4" title="Destructeur par defaut.">baseClientServer::~baseClientServer</a>()
<a name="l00050"></a>00050 {
<a name="l00051"></a>00051     <a class="code" href="classbase_client_server.html#a6415a999d34d9969e6b7d7108df74c0f">IF_WINDOWS</a>(
<a name="l00052"></a>00052         <span class="comment">// Arrêt de WinSock</span>
<a name="l00053"></a>00053         <span class="keywordflow">if</span>( WSACleanup() == SOCKET_ERROR )
<a name="l00054"></a>00054             stdErrorE(<span class="stringliteral">&quot;Erreur(%d) lors de l&#39;arrêt de WinSock&quot;</span>, SOCKET_REPPORT_ERROR);
<a name="l00055"></a>00055     )
<a name="l00056"></a>00056 }
<a name="l00057"></a>00057 
<a name="l00058"></a>00058 
<a name="l00059"></a>00059 <span class="comment">/***************************************************************************/</span><span class="comment">/*!</span>
<a name="l00060"></a>00060 <span class="comment">* @fn void baseClientServer::setPort( unsigned int port )</span>
<a name="l00061"></a>00061 <span class="comment">* @brief Modifier le port d&#39;écoute</span>
<a name="l00062"></a>00062 <span class="comment">* @param[in] port Le port a utiliser de 1 à 65 536</span>
<a name="l00063"></a>00063 <span class="comment">* @note Par défaut, le port = 0 =&gt; port alléatoire.</span>
<a name="l00064"></a>00064 <span class="comment">*/</span>
<a name="l00065"></a><a class="code" href="classbase_client_server.html#ae24984bbf180c9fe1e75160e108dbaa4">00065</a> <span class="keywordtype">void</span> <a class="code" href="classbase_client_server.html#ae24984bbf180c9fe1e75160e108dbaa4" title="Modifier le port d&amp;#39;écoute.">baseClientServer::setPort</a>( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="classbase_client_server.html#a61011c973d5f71ddd0894f1f99f8959e" title="Defini le port à utiliser.">port</a> )
<a name="l00066"></a>00066 {
<a name="l00067"></a>00067     <span class="keywordflow">if</span>( port &gt; 65536 )
<a name="l00068"></a>00068         reportError(<span class="stringliteral">&quot;Vous ne pouvez pas indiquer un port &gt; à 65 536&quot;</span>);
<a name="l00069"></a>00069     <a class="code" href="classbase_client_server.html#a2dea81cee139f918358e36b8650fa37e" title="&amp;lt; Temps d&amp;#39;attente au niveau du select">c_port</a> = port;
<a name="l00070"></a>00070 }
<a name="l00071"></a>00071 
<a name="l00072"></a>00072 
<a name="l00073"></a>00073 <span class="comment">/***************************************************************************/</span><span class="comment">/*!</span>
<a name="l00074"></a>00074 <span class="comment">* @fn void baseClientServer::setWait( long tv_sec, long tv_usec )</span>
<a name="l00075"></a>00075 <span class="comment">* @brief Modifier le temps d&#39;attente d&#39;une réponse</span>
<a name="l00076"></a>00076 <span class="comment">* @param[in] tv_sec Le temps en secs</span>
<a name="l00077"></a>00077 <span class="comment">* @param[in] tv_usec Le temps en ms</span>
<a name="l00078"></a>00078 <span class="comment">* @note Le temps d&#39;attente par défaut est de 0.01sec</span>
<a name="l00079"></a>00079 <span class="comment">*/</span>
<a name="l00080"></a><a class="code" href="classbase_client_server.html#acf92891d022c8c20e68b634ba1701757">00080</a> <span class="keywordtype">void</span> <a class="code" href="classbase_client_server.html#acf92891d022c8c20e68b634ba1701757" title="Modifier le temps d&amp;#39;attente d&amp;#39;une réponse.">baseClientServer::setWait</a>( <span class="keywordtype">long</span> tv_sec, <span class="keywordtype">long</span> tv_usec )
<a name="l00081"></a>00081 {
<a name="l00082"></a>00082     <span class="keywordflow">if</span>( tv_sec &lt; 0 || tv_usec &lt; 0 )
<a name="l00083"></a>00083         reportError(<span class="stringliteral">&quot;Temps d&#39;attente incorrect !&quot;</span>);
<a name="l00084"></a>00084 
<a name="l00085"></a>00085     c_wait.tv_sec = tv_sec;
<a name="l00086"></a>00086     c_wait.tv_usec = tv_usec;
<a name="l00087"></a>00087 }
<a name="l00088"></a>00088 
<a name="l00089"></a>00089 
<a name="l00090"></a>00090 <span class="comment">/***************************************************************************/</span><span class="comment">/*!</span>
<a name="l00091"></a>00091 <span class="comment">* @fn int baseClientServer::readClient( SOCKET sock, char* buffer, unsigned int bufferSize )</span>
<a name="l00092"></a>00092 <span class="comment">* @brief Récupère les données envoyées par un client</span>
<a name="l00093"></a>00093 <span class="comment">* @param[in] sock Le socket du client</span>
<a name="l00094"></a>00094 <span class="comment">* @param[in,out] buffer La variables où seront stockées les données</span>
<a name="l00095"></a>00095 <span class="comment">* @param[in] bufferSize Taille du buffer</span>
<a name="l00096"></a>00096 <span class="comment">* @return Le nombre de byte reçut</span>
<a name="l00097"></a>00097 <span class="comment">*</span>
<a name="l00098"></a>00098 <span class="comment">* @note si retour = 0 =&gt; Client déconnecté (Le client est automatiquement viré de la liste dans ce cas la)&lt;br /&gt;</span>
<a name="l00099"></a>00099 <span class="comment">* En cas d&#39;erreur, le client sera déconnecté</span>
<a name="l00100"></a>00100 <span class="comment">*/</span>
<a name="l00101"></a><a class="code" href="classbase_client_server.html#a6eeb24edfb7b92dd6311817d848bb953">00101</a> <span class="keywordtype">int</span> <a class="code" href="classbase_client_server.html#a6eeb24edfb7b92dd6311817d848bb953" title="Récupère les données envoyées par un client.">baseClientServer::readClient</a>( <a class="code" href="class___base_client_server_8h.html#a8dc8083897335125630f1af5dafd5831">SOCKET</a> sock, <span class="keywordtype">char</span>* buffer, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> bufferSize )
<a name="l00102"></a>00102 {
<a name="l00103"></a>00103     <span class="keywordtype">int</span> nbByte = recv(sock, buffer, bufferSize, 0);
<a name="l00104"></a>00104 
<a name="l00105"></a>00105     stdError(<span class="stringliteral">&quot;rcv %s&quot;</span>, buffer);
<a name="l00106"></a>00106 
<a name="l00107"></a>00107     <span class="keywordflow">if</span>( nbByte == SOCKET_ERROR ){
<a name="l00108"></a>00108         stdError(<span class="stringliteral">&quot;Erreur(%d) lors de la lecture du client %d. Detail: &lt;%s&gt;&quot;</span>, SOCKET_REPPORT_ERROR, sock, strerror(SOCKET_REPPORT_ERROR));
<a name="l00109"></a>00109         nbByte = 0;<span class="comment">// if recv error we disonnect the client</span>
<a name="l00110"></a>00110     }
<a name="l00111"></a>00111 
<a name="l00112"></a>00112     <span class="keywordflow">return</span> nbByte;
<a name="l00113"></a>00113 }
<a name="l00114"></a>00114 
<a name="l00115"></a>00115 
<a name="l00116"></a>00116 <span class="comment">/***************************************************************************/</span><span class="comment">/*!</span>
<a name="l00117"></a>00117 <span class="comment">* @fn void baseClientServer::send_message( SOCKET sock, const char* buffer, unsigned int bufferSize )</span>
<a name="l00118"></a>00118 <span class="comment">* @brief Envoie un message (buffer) au client</span>
<a name="l00119"></a>00119 <span class="comment">* @param[in] sock Le socket du client</span>
<a name="l00120"></a>00120 <span class="comment">* @param[in,out] buffer La variable sont stockées les données à envoyer</span>
<a name="l00121"></a>00121 <span class="comment">* @param[in] bufferSize Taille du buffer</span>
<a name="l00122"></a>00122 <span class="comment">*/</span>
<a name="l00123"></a><a class="code" href="classbase_client_server.html#afaeac42db5822c4582e54e51daaa35a8">00123</a> <span class="keywordtype">void</span> <a class="code" href="classbase_client_server.html#afaeac42db5822c4582e54e51daaa35a8" title="Envoie un message (buffer) au client.">baseClientServer::send_message</a>( <a class="code" href="class___base_client_server_8h.html#a8dc8083897335125630f1af5dafd5831">SOCKET</a> sock, <span class="keyword">const</span> <span class="keywordtype">char</span>* buffer, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> bufferSize )
<a name="l00124"></a>00124 {
<a name="l00125"></a>00125     stdError(<span class="stringliteral">&quot;send %s&quot;</span>, buffer);
<a name="l00126"></a>00126     <span class="keywordflow">if</span>( send(sock, buffer, bufferSize, 0) == SOCKET_ERROR )
<a name="l00127"></a>00127        stdError(<span class="stringliteral">&quot;Erreur(%d) lors de l&#39;envoie du message. Detail: &lt;%s&gt;&quot;</span>, SOCKET_REPPORT_ERROR, strerror(SOCKET_REPPORT_ERROR));
<a name="l00128"></a>00128 }
<a name="l00129"></a>00129 
<a name="l00130"></a>00130 
<a name="l00131"></a>00131 <span class="comment">//***************************************************************************//*!</span>
<a name="l00132"></a>00132 <span class="comment">//* @fn template&lt;class Type&gt; Type baseClientServer::reverseBit( Type var )</span>
<a name="l00133"></a>00133 <span class="comment">//* @brief Inverse les bits.</span>
<a name="l00134"></a>00134 <span class="comment">//* @param[in] var La variable a qui il faut inversé les bits</span>
<a name="l00135"></a>00135 <span class="comment">//* @return Renvoie la {var} avec les bits inversé</span>
<a name="l00136"></a>00136 <span class="comment">//* @warning FONCTION commenté car Innutile pour l&#39;instant</span>
<a name="l00137"></a>00137 <span class="comment">//*/</span>
<a name="l00138"></a>00138 <span class="comment">/*</span>
<a name="l00139"></a>00139 <span class="comment">template&lt;class Type&gt; Type baseClientServer::reverseBit( Type var )// Inverse les bits</span>
<a name="l00140"></a>00140 <span class="comment">{</span>
<a name="l00141"></a>00141 <span class="comment">    const unsigned int nbByte = sizeof(Type)*CHAR_BIT;</span>
<a name="l00142"></a>00142 <span class="comment"></span>
<a name="l00143"></a>00143 <span class="comment">    Type out = 0;</span>
<a name="l00144"></a>00144 <span class="comment">    unsigned int i=0;</span>
<a name="l00145"></a>00145 <span class="comment"></span>
<a name="l00146"></a>00146 <span class="comment">    do{</span>
<a name="l00147"></a>00147 <span class="comment">        out|= var&amp;0x01;     //copie du bit de poids faible</span>
<a name="l00148"></a>00148 <span class="comment">        i++;                //compter les bits copiés</span>
<a name="l00149"></a>00149 <span class="comment">        if( i == nbByte)    //si tous les bits sont traités...</span>
<a name="l00150"></a>00150 <span class="comment">            break;          //...arrêter</span>
<a name="l00151"></a>00151 <span class="comment">        var &gt;&gt;= 1;          //vider vers la droite (préparer le suivant)...</span>
<a name="l00152"></a>00152 <span class="comment">        out&lt;&lt;= 1;           //...pour remplir vers la gauche (préparer la place)</span>
<a name="l00153"></a>00153 <span class="comment">    }while(1);</span>
<a name="l00154"></a>00154 <span class="comment"></span>
<a name="l00155"></a>00155 <span class="comment">    return out;</span>
<a name="l00156"></a>00156 <span class="comment">}</span>
<a name="l00157"></a>00157 <span class="comment">*/</span>
<a name="l00158"></a>00158 
<a name="l00159"></a>00159 
<a name="l00160"></a>00160 <span class="comment">/***************************************************************************/</span><span class="comment">/*!</span>
<a name="l00161"></a>00161 <span class="comment">* @fn template&lt;class Type&gt; Type baseClientServer::reverseByte( Type var )</span>
<a name="l00162"></a>00162 <span class="comment">* @brief Conversion Little Endian &lt;-&gt; Big Endian (Inversion des octets)</span>
<a name="l00163"></a>00163 <span class="comment">* @param[in] var La variable a qui il faut inversé les octets</span>
<a name="l00164"></a>00164 <span class="comment">* @return Renvoie la {var} avec les octets inversé</span>
<a name="l00165"></a>00165 <span class="comment">*/</span>
<a name="l00166"></a><a class="code" href="classbase_client_server.html#ad64908eb927871b5d9544ea664d6d5ce">00166</a> <span class="keyword">template</span>&lt;<span class="keyword">class</span> Type&gt; Type <a class="code" href="classbase_client_server.html#ad64908eb927871b5d9544ea664d6d5ce" title="Conversion Little Endian &amp;lt;-&amp;gt; Big Endian (Inversion des octets).">baseClientServer::reverseByte</a>( Type var )<span class="comment">// Inverse les octets</span>
<a name="l00167"></a>00167 {
<a name="l00168"></a>00168     Type out = 0;
<a name="l00169"></a>00169     <span class="keyword">const</span>   <span class="keywordtype">char</span>* pIn = (<span class="keyword">const</span>      <span class="keywordtype">char</span>*) &amp;var;
<a name="l00170"></a>00170             <span class="keywordtype">char</span>* pOut= (           <span class="keywordtype">char</span>*)(&amp;out+1)-1;
<a name="l00171"></a>00171 
<a name="l00172"></a>00172     <span class="keywordflow">for</span>( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i=<span class="keyword">sizeof</span>(Type); i&gt;0 ; i-- )
<a name="l00173"></a>00173     {
<a name="l00174"></a>00174         *pOut-- = *pIn++;
<a name="l00175"></a>00175     }
<a name="l00176"></a>00176     <span class="keywordflow">return</span> out;
<a name="l00177"></a>00177 }
<a name="l00178"></a>00178 
<a name="l00179"></a>00179 
<a name="l00180"></a>00180 <span class="comment">/***************************************************************************/</span><span class="comment">/*!</span>
<a name="l00181"></a>00181 <span class="comment">* @fn bool baseClientServer::isLittleEndian()</span>
<a name="l00182"></a>00182 <span class="comment">* @brief Permet de savoir si l&#39;on est sur une machine Intel, une machine qui lit</span>
<a name="l00183"></a>00183 <span class="comment">* les octects en Little Endian.</span>
<a name="l00184"></a>00184 <span class="comment">* @see baseClientServer::reverseByte( Type var )</span>
<a name="l00185"></a>00185 <span class="comment">*/</span>
<a name="l00186"></a><a class="code" href="classbase_client_server.html#a09c15f21a6970e5a5f9103802291c502">00186</a> <span class="keywordtype">bool</span> <a class="code" href="classbase_client_server.html#a09c15f21a6970e5a5f9103802291c502" title="Permet de savoir si l&amp;#39;on est sur une machine Intel, une machine qui lit les octects en Little End...">baseClientServer::isLittleEndian</a>()<span class="comment">// isIntel</span>
<a name="l00187"></a>00187 {
<a name="l00188"></a>00188     <span class="keywordtype">long</span> l = 1;
<a name="l00189"></a>00189     <span class="keywordflow">return</span> (<span class="keywordtype">bool</span>) *((<span class="keywordtype">char</span> *)(&amp;l));
<a name="l00190"></a>00190 }
<a name="l00191"></a>00191 
<a name="l00192"></a>00192 
<a name="l00193"></a>00193 <span class="comment">/***************************************************************************/</span><span class="comment">/*!</span>
<a name="l00194"></a>00194 <span class="comment">* @fn void baseClientServer::setTCP_NoDelay( SOCKET s, bool activer )</span>
<a name="l00195"></a>00195 <span class="comment">* @brief Permet de modifier le paramètre TCP_NoDelay ( Algorithme de Nagle )</span>
<a name="l00196"></a>00196 <span class="comment">* @param[in] s Le socket a modifier</span>
<a name="l00197"></a>00197 <span class="comment">* @param[in] activer Désactiver ?</span>
<a name="l00198"></a>00198 <span class="comment">*/</span>
<a name="l00199"></a><a class="code" href="classbase_client_server.html#a702e328a02579aac6a8060a2b18838f0">00199</a> <span class="keywordtype">void</span> <a class="code" href="classbase_client_server.html#a94f59ec6bf09f3c90f25e57781632df5">baseClientServer::setTCP_NoDelay</a>( <a class="code" href="class___base_client_server_8h.html#a8dc8083897335125630f1af5dafd5831">SOCKET</a> s, <span class="keywordtype">bool</span> activer )
<a name="l00200"></a>00200 {
<a name="l00201"></a>00201     <a class="code" href="classbase_client_server.html#a6415a999d34d9969e6b7d7108df74c0f">IF_WINDOWS</a>(
<a name="l00202"></a>00202         <span class="keywordtype">char</span> use = (<span class="keywordtype">char</span>)activer;
<a name="l00203"></a>00203     )
<a name="l00204"></a>00204     IF_LINUX(
<a name="l00205"></a>00205         <span class="keywordtype">int</span> use = (<span class="keywordtype">int</span>)activer;
<a name="l00206"></a>00206     )
<a name="l00207"></a>00207     <span class="keywordflow">if</span>( setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &amp;use, <span class="keyword">sizeof</span>(use)) == SOCKET_ERROR )
<a name="l00208"></a>00208         reportError(<span class="stringliteral">&quot;Erreur(%d). Impossible de modifier l&#39;utilisation de l&#39;Algorithme de Nagle ! setsockopt(). Detail: &lt;%s&gt;&quot;</span>, SOCKET_REPPORT_ERROR, strerror(SOCKET_REPPORT_ERROR));
<a name="l00209"></a>00209 }
<a name="l00210"></a>00210 
<a name="l00211"></a>00211 
<a name="l00212"></a>00212 <span class="comment">/***************************************************************************/</span><span class="comment">/*!</span>
<a name="l00213"></a>00213 <span class="comment">* @fn bool baseClientServer::TCP_NoDelay( SOCKET s )</span>
<a name="l00214"></a>00214 <span class="comment">* @brief Permet de savoir l&#39;état du paramètre TCP_NoDelay ( Algorithme de Nagle )</span>
<a name="l00215"></a>00215 <span class="comment">* @param[in] s Le socket a analyser</span>
<a name="l00216"></a>00216 <span class="comment">*/</span>
<a name="l00217"></a><a class="code" href="classbase_client_server.html#a7d8a192e4011ea46b9d36ab8e2c921e1">00217</a> <span class="keywordtype">bool</span> <a class="code" href="classbase_client_server.html#a676e6d281c3ff4a5c9e2b91c04d6b99a" title="Permet de savoir l&amp;#39;état du paramètre TCP_NoDelay ( Algorithme de Nagle ) pour le socket c_listenS...">baseClientServer::TCP_NoDelay</a>( <a class="code" href="class___base_client_server_8h.html#a8dc8083897335125630f1af5dafd5831">SOCKET</a> s )
<a name="l00218"></a>00218 {
<a name="l00219"></a>00219     <a class="code" href="classbase_client_server.html#a6415a999d34d9969e6b7d7108df74c0f">IF_WINDOWS</a>(
<a name="l00220"></a>00220         <span class="keywordtype">int</span> optLen = <span class="keyword">sizeof</span>(<span class="keywordtype">char</span>);
<a name="l00221"></a>00221         <span class="keywordtype">char</span> use = 0;
<a name="l00222"></a>00222     )
<a name="l00223"></a>00223     IF_LINUX(
<a name="l00224"></a>00224         <span class="keywordtype">int</span> use = 0;
<a name="l00225"></a>00225         <a class="code" href="class___base_client_server_8h.html#a6b82106923cc13b3a9734520ecc29514">socklen_t</a> optLen = <span class="keyword">sizeof</span>(socklen_t);
<a name="l00226"></a>00226     )
<a name="l00227"></a>00227     <span class="keywordflow">if</span>( getsockopt(s, IPPROTO_TCP, TCP_NODELAY, &amp;use, &amp;optLen) == SOCKET_ERROR )
<a name="l00228"></a>00228         reportError(<span class="stringliteral">&quot;Erreur(%d). Impossible d&#39;accèder au paramètre de l&#39;Algorithme de Nagle ! getsockopt(). Detail: &lt;%s&gt;&quot;</span>, SOCKET_REPPORT_ERROR, strerror(SOCKET_REPPORT_ERROR));
<a name="l00229"></a>00229 
<a name="l00230"></a>00230     <span class="keywordflow">return</span> (<span class="keywordtype">bool</span>)use;
<a name="l00231"></a>00231 }
<a name="l00232"></a>00232 
<a name="l00233"></a>00233 
<a name="l00234"></a>00234 <span class="comment">/***************************************************************************/</span><span class="comment">/*!</span>
<a name="l00235"></a>00235 <span class="comment">* @fn void baseClientServer::printAllBuffer( const char buffer[], unsigned int bufferSize, const char file[], unsigned int line )</span>
<a name="l00236"></a>00236 <span class="comment">* @brief Permet de voir TOUT le buffer</span>
<a name="l00237"></a>00237 <span class="comment">* @param[in] buffer     Le buffer a afficher</span>
<a name="l00238"></a>00238 <span class="comment">* @param[in] bufferSize La taille du buffer. [0 à bufferSize[</span>
<a name="l00239"></a>00239 <span class="comment">* @param[in] file       Le fichier d&#39;où est appelé la fonction (__FILE__)</span>
<a name="l00240"></a>00240 <span class="comment">* @param[in] line       La ligne du fichier d&#39;où est appelé la fonction (__LINE__)</span>
<a name="l00241"></a>00241 <span class="comment">*/</span>
<a name="l00242"></a>00242 <span class="keywordtype">void</span> baseClientServer::printAllBuffer( <span class="keyword">const</span> <span class="keywordtype">char</span> buffer[], <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> bufferSize, <span class="keyword">const</span> <span class="keywordtype">char</span> file[], <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> line )
<a name="l00243"></a>00243 {
<a name="l00244"></a>00244     fprintf(stderr, <span class="stringliteral">&quot;[file %s, line %u]: Paquet:&lt;&quot;</span>, file, line);
<a name="l00245"></a>00245     <span class="keywordflow">for</span>( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i=0; i&lt;bufferSize; i++ )
<a name="l00246"></a>00246         fprintf(stderr, <span class="stringliteral">&quot;%c&quot;</span>, buffer[i]);
<a name="l00247"></a>00247     fprintf(stderr, <span class="stringliteral">&quot;&gt;\n&quot;</span>);
<a name="l00248"></a>00248 }
</pre></div></div>
</div>
<hr class="footer"/><address class="footer"><small>Généré le Fri Jan 21 2011 01:21:27 pour Bomberman par&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.1 </small></address>
</body>
</html>
